<?php
namespace app\common\model;
class Article extends Base{
    function getVipLevelAttr($v){
        return is_null($v)?0:$v;
    }
    
    function getAuthorAttr($v){
        return is_null($v)?'':$v;
    }
    function author(){
        return $this->belongsTo('member','uid')->bind(['author'=>'name','vip_level','head_img'])->field('id,name,vip_level,head_img');
    }
    function module(){
        return $this->belongsTo('artmodule','module_id')->bind(['module'=>'title'])->field('id,title');
    }
    function cate(){
        return $this->belongsTo('artcate','cate_id')->bind(['cate'=>'name'])->field('id,name');
    }
    function tag(){
        return $this->belongsTo('arttags','tag_id')->bind(['tag'=>'name','tag_icon'=>'icon'])->field('id,name,icon');
    }
    function praise(){
        return $this->hasOne('praise','product_id')->bind(['is_praise'=>'type'])->field('product_id,convert(type,char(1)) as type');
    }
    function images(){
        return $this->hasMany('media','product_id')->field('id,product_id,link');
    }
}
